﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Rbac.Project.Application;
using Rbac.Project.Application.Admins;
using Rbac.Project.Application.Admins.Dto;
using Rbac.Project.WebApi.Filters;
using System.Threading.Tasks;

namespace Rbac.Project.WebApi.Controllers
{
    [Route("/[controller]/[action]")]
    [ApiController]
    //[CustomerAuthorizationFilter]
    public class AdminController : ControllerBase
    {
        public IAdminService adminService { get; set; }

        /*public AdminController(IAdminService adminService)
        {
            this.adminService = adminService;
        }*/

        public ITestService  testService { get; set; }

        [HttpPost]
        public async Task<IActionResult> Create(CreateOrUpdateDto dto)
        {
            return Ok(await adminService.InsertAsync(dto));
        }

        /*[HttpGet]
        public IActionResult DiTest()
        {
            testService.Test();
            return Ok();
		}*/

        [HttpPost]
        [AllowAnonymous]
        public async Task<IActionResult> LoginAsync(LoginDto dto)
        {
			//加日志

			return Ok(await adminService.LoginAsync(dto));
        }

        [HttpGet]
        public async Task<IActionResult> PageAsync([FromQuery]QueryDto dto, int PageIndex = 1, int PageSize = 10)
        {
            return Ok(await adminService.PageDataTupleAsync(dto, PageIndex, PageSize));
        }

        [HttpGet]
        public async Task<IActionResult> FindAsync(int AdminId)
        {
			//加日志

			return Ok(await adminService.FindAsync(AdminId));
        }

        /// <summary>
        /// Resuful
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> DeleteAsync(int Id)
        {
			//加日志

			return Ok(await adminService.DeleteAsync(Id));
        }
    }
}
